#! /bin/sh
#
PROG="$(basename $0)"

usage () {
cat <<EOF
Usage: $PROG

Download and install all required software for 'mgn.sh' to
work into the "`pwd`/sw" directory.

EOF
}


## helper functions
die () {
  rc="$1"
  shift
  (echo -n "$PROG: ERROR: ";
      if [ $# -gt 0 ]; then echo "$@"; else cat; fi) 1>&2
  exit $rc
}

have_command () {
  type "$1" >/dev/null 2>/dev/null
}

require_command () {
  if ! have_command "$1"; then
    die 1 "Could not find required command '$1' in system PATH. Aborting."
  fi
}

_ () {
    echo
    echo ==== "$@";
}


## parse command-line 

if [ $# -ne 0 ]; then
  usage
  exit 0
fi


## main

require_command bunzip2
require_command gunzip
require_command tar
require_command wget

set -e

mkdir -p sw
cd sw


CYTHON=Cython-0.11.1
_ Downloading Cython 0.11.1 (from http://www.cython.org/${CYTHON}.tar.gz) ...
wget -N http://www.cython.org/${CYTHON}.tar.gz

_ Installing Cython ...
gunzip ${CYTHON}.tar.gz
tar -x -f ${CYTHON}.tar
cd ${CYTHON}
python setup.py build

PYTHONPATH=$PYTHONPATH:`pwd`; export PYTHONPATH
PATH=$PATH:`pwd`/bin; export PATH


